home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cgazv5n5.arc / LIST6.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  1KB  |  46 lines

  1. /*---------------------------------------- Listing 6 ------
  2.  * An intelligent control-break handler.
  3.  * See Listing 1 for copyright terms.
  4.  *-------------------------------------------------------*/
  5. #include <stdio.h>
  6. #include <signal.h>
  7.  
  8. void CtlBrkHandler ( int Signal, int SubCode );
  9. void main ( void );
  10.  
  11. void CtlBrkHandler ( int Signal, int SubCode )
  12. {
  13.     /*---------------------------------------------------------
  14.      * Without the following line, Control-Break would by now 
  15.      * be reset to default, and the program would quit.        
  16.      *-------------------------------------------------------*/
  17.  
  18.     signal ( SIGINT, SIG_IGN );
  19.     printf( "Signal %d, SubCode %d was raised\n", 
  20.              Signal, SubCode);
  21.  
  22.     /*---------------------------------------------------------
  23.      * The following Control-Break (explicitly raised) 
  24.      * will be ignored!
  25.      *-------------------------------------------------------*/
  26.  
  27.     raise ( SIGINT );
  28.  
  29.     /*---------------------------------------------------------
  30.      * Leaving the handler, we can reactivate Control-Break 
  31.      * for future use.
  32.      *-------------------------------------------------------*/
  33.  
  34.     signal ( SIGINT, CtlBrkHandler );
  35. }
  36.  
  37. void main ( void )
  38. {
  39.     void (*OldHandler) ( int Signal );
  40.  
  41.     OldHandler = signal ( SIGINT, CtlBrkHandler );
  42.     if ( OldHandler == SIG_ERR )
  43.         printf ( "signal failed\n" );
  44.  
  45.     raise ( SIGINT );
  46. }